@extends('layout.default')

@section('layout.content')
  <div class="row">
    <div class="col-xs-12">
      <form class="form-horizontal" id="staff-create" autocomplete="off">
        {{ csrf_field() }}
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="username"> <b><span class="red">*</span> 账户：</b>
          </label>
          <div class="col-sm-4">
            <input type="text" class="form-control" id="username" name="username" placeholder="账户"/>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="name"> 名称：</label>
          <div class="col-sm-4">
            <input type="text" class="form-control" id="name" name="name" placeholder="名称"/>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="name"> <b><span
                  class="red">*</span>所属分支：</b></label>
          <div class="col-sm-6">
            @foreach($branches as $key=>$branch)
              <div class="radio-inline">
                <label>
                  <input name="branch" type="radio" value="{{$branch->id}}" class="ace"/>
                  <span class="lbl" style="width:100px;"> {{$branch->name}}</span>
                </label>
              </div>
            @endforeach
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="name"> 角色：</label>
          <div class="col-sm-6">
            @foreach($roles as $key=>$role)
              <div class="checkbox-inline">
                <label>
                  <input name="role" type="checkbox" value="{{$role->id}}" class="ace ace-checkbox-2"/>
                  <span class="lbl"> {{$role->name}}</span>
                </label>
              </div>
            @endforeach
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right"> </label>
          <div class="col-sm-4">
            <button type="button" class="btn btn-primary submit">
              <i class="ace-icon fa fa-check"></i>
              <span class="">确定</span>
            </button>
          </div>
        </div>

      </form>
    </div>
  </div>

@stop

@section('javascript')
  <script type="text/javascript">
      $(function () {

          $('.submit').on('click', function () {
              var roles = new Array();
              $("input:checkbox[name='role']:checked").each(function () {
                  roles.push($(this).val());
              });

              var uri = '{{route('system.staff.store')}}';

              $.post(uri, {
                  '_token': $("input[name='_token']").attr('value'),
                  'username': $("input[name='username']").val(),
                  'branch': $("input:radio[name='branch']:checked").val(),
                  'roles': roles,
                  'is_submit': true
              }, function (data) {
                  layer.msg(data.message, {shift: -1}, function () {
                      if (data.status === true && data.url != null) {
                          $(window).attr('location', data.url);
                      }
                  });

              }, 'json').error(function (data) {
                  layer.msg(data.responseJSON.message);
              });

          });


      });
  </script>
@stop